let resultSet = new Set();

let intervalId;

let isRunning = false;

const people = ["田小宇", "许高寒", "程宏扬", "万朕"
    , "王依格", "王友好", "阮航", "王瑾"
    , "陈伊", "唐优扬", "李镁淇", "胡思银"
    , "蒋新武", "时燕琳", "邢俊杰", "朱瑞"]


document.getElementById('btn').addEventListener('click', function () {
    if (isRunning) {
        clearInterval(intervalId);
        if (people.length != resultSet.size) {
            let randomPerson;
            do {
                const randomIndex = Math.floor(Math.random() * people.length);
                randomPerson = people[randomIndex];
            } while (resultSet.has(randomPerson))

            document.getElementById('result').innerText = randomPerson;
            resultSet.add(randomPerson);
            const span = document.createElement('span');
            span.className = 'listItem'
            span.innerText = randomPerson;
            document.getElementsByClassName('list')[0].appendChild(span);
        } else {
            alert("全抽完了");
        }
        isRunning = false;
        btn.innerText = "开始"
    } else {
        intervalId = setInterval(() => {
            const randomIndex = Math.floor(Math.random() * people.length);
            const randomPerson = people[randomIndex];
            document.getElementById('result').innerText = randomPerson;
        }, 50);
        isRunning = true;
        btn.innerText = "停止"
    }

})

